<?php

class ControllerAccountQuestion extends Controller
{
    private $error = array();

    public function getQuestions(){
        if (! $this->actionCheck(true, false)) {
            return;
        }
        $this->load->model('account/question');
        $data =  $this->model_account_question->getQuestions();
        foreach ($data as &$item){
            $customer_question = $this->db->query("select DISTINCT * from customer_question where customer_id = '".(int)$this->customer->getId()."' and question_id = '".(int)$item['question_id']."' ")->row;
            if($customer_question){
                $item['read'] = 1;
            }else{
                $item['read'] = 0;
            }
        }
        $this->response->setDataResult(1, '成功', $data);
    }

    public function getQuestion(){
        if (! $this->actionCheck(true, true)) {
            return;
        }
        if((int)$this->request->post['question_id']==0){
            $this->response->setDataResult(0, '失败', null);
            return;
        }
        $customer_question = $this->db->query("select * from customer_question where question_id = '".$this->request->post['question_id']."' and customer_id = '".(int)$this->customer->getId()."'")->row;
        if(!$customer_question){
            $this->db->query("insert into customer_question SET question_id = '".$this->request->post['question_id']."',customer_id = '".(int)$this->customer->getId()."' ");
            $this->response->setDataResult(1, '成功', $this->db->getLastId());
        }else{
            $this->response->setDataResult(1, '成功', null);
        }

    }

}